//package com.share.simple.provider;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Lazy;
//import org.springframework.security.authentication.AuthenticationProvider;
//import org.springframework.security.authentication.BadCredentialsException;
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.AuthenticationException;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.crypto.password.PasswordEncoder;
//import org.springframework.stereotype.Component;
//
///**
// * 认证管理器 通过manager代理处理认证
// * @author:caifan
// * @since 2023/7/10
// */
////@Component
//public class CustomAuthenticationProvider implements AuthenticationProvider {
//
//    @Lazy
//    @Autowired
//    private UserDetailsService userDetailsService;
//
//    @Lazy
//    @Autowired
//    private PasswordEncoder passwordEncoder;
//
//
//    @Override
//    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
//        String username = authentication.getName();
//        String password = authentication.getCredentials().toString();
//
//        UserDetails user = userDetailsService.loadUserByUsername(username);
//        // 密码匹配
//        if (passwordEncoder.matches(password, user.getPassword())) {
//            return new UsernamePasswordAuthenticationToken(username, password, user.getAuthorities());
//        } else {
//            throw new BadCredentialsException("The username or password is wrong!");
//        }
//    }
//
//    @Override
//    public boolean supports(Class<?> authentication) {
////        authentication.isAssignableFrom(CustomAuthenticationProvider.class)
////        return authentication.equals(UsernamePasswordAuthenticationToken.class);
//        return UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication);
//    }
//
//}
